/*
 * interviewTestSuite.cpp
 *
 *  Created on: 2013-1-14
 *      Author: EthanHuang
 */

#include <iostream>
#include "cute.h"
#include "ide_listener.h"
#include "cute_runner.h"
#include "interviewTestSuite.h"
#include "InterviewAlgorithm.h"
#include "BasicUtility.h"
#include "InsertSort.h"
#include "QuickSort.h"
#include "AVLTree.h"
#include "BinaryHeap.h"
#include "FunctionObjects.h"
using namespace std;


//testcase: count the numbers of a integer i in an array
void countOfKTest()
{
	vector<int> array(4, 2);
	array[3] = 5;
	CountNumberK obj;
	int count = obj(array, 2);
	ASSERT_EQUALM("The count of number", 3, count);
}r

//Testcase: to print a arr[2][4] in cycles
void thisIsMatrixPrintCycleTest() {
	//Initialize the matrix
	int **arr = new int*[2];
	for(int i = 0; i < 2; ++i)
	{
		arr[i] = new int [4];
	}
	for(int i=0; i < 2; ++i)
	{
		for(int j=0; j < 4; ++j)
		{
			arr[i][j] = j + 4 * i;
		}
	}

	//print the matrix
	cout<<"The matrix is: "<<endl;
	for(int i = 0; i < 2; ++i)
	{
		for(int j = 0; j < 4; ++j)
		{
			cout<<arr[i][j]<<" ";
		}
		cout<<endl;
	}
	InterviewAlgorithm::printMatrixInCycles(arr, 2, 4);
	ASSERTM("start sort test", true);
	for(int i = 0; i < 2; ++i)
	{
		delete arr[i];
	}
	delete arr;
}

//Test case: test merge sort
void thisIsMergeSortTester()
{
	int a[10] = {32, 21, 3, 5, 6, 7, 232, 113, 34, 55};
	std::cout<<"Before merge sort: "<<endl;
	BasicUtility::printIntArray(a, 10);
	InterviewAlgorithm::mergeSortDriver(a, 10);
	std::cout<<"After merge sort: "<<endl;
	BasicUtility::printIntArray(a, 10);
	ASSERTM("start merge sort test", false);
}

void InsertSortTest()
{
	int a[10] = {55, 44, 33, 12, 56, 7, 82, 9, 1002, 1};
	InsertSort sort;
	sort(a, 0, 9);
	for(int i = 0; i < 10; ++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<endl;
	ASSERTM("Insert Sort Test", false);
}

void QuickSortTest()
{
	int a[20] = {55, 44, 525, 444, 393, 122, 5116, 263, 182, 2389, 102, 329, 732, 356, 17, 682, 29, 2002, 111, 31};
	QuickSort sort;
	sort(a, 0, 19);
	for(int i = 0; i < 20; ++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<endl;
	ASSERTM("Quick Sort Test", false);
}

void AVLTreeTest()
{
	AVLTree<int> tree;
	tree.printTree();
	tree.insert(3);
	tree.printTree();
	tree.insert(6);
	tree.printTree();
	tree.insert(7);
	tree.printTree();
	tree.insert(8);
	tree.printTree();
	tree.insert(9);
	tree.printTree();
	ASSERTM("AVLTree Test", false);
}

void BinaryHeapTest()
{
	BinaryHeap heap;
	heap.insert(3);
	heap.insert(2);
	heap.insert(8);
	heap.insert(4);
	heap.print();
	int min = heap.findMin();
	std::cout<<"the min is"<<min<<std::endl;
	heap.deleteMin();
	heap.print();
	ASSERTM("BinaryHeap Test", false);
}

void make_suite_InterviewTestSuite(){
	cute::suite s;
	//s.push_back(CUTE(thisIsMatrixPrintCycleTest));
	//s.push_back(CUTE(thisIsMergeSortTester) );
	//s.push_back(CUTE(QuickSortTest));
	//s.push_back(CUTE(AVLTreeTest));
	//s.push_back(CUTE(BinaryHeapTest));
	s.push_back(CUTE(countOfKTest));
	cute::ide_listener lis;
	cute::makeRunner(lis)(s, "The Suite interview");
	//return s;
}

